package day04;

import java.util.Arrays;
import java.util.Scanner;

/**
 * 成绩管理
 */
public class ScoreManager {
    public static void main(String[] args) {
        String[] names = new String[5];
        double[] scores = new double[names.length];
        addStudent(names);
        addScore(names,scores);
        System.out.println(Arrays.toString(names));
        System.out.println(Arrays.toString(scores));
        Scanner sca = new Scanner(System.in);
        while(true){
            System.out.println("请输入要查询的学生姓名:");
            String name = sca.next();
            double score = selectScoreByName(names,scores,name);
            if(score<0){
                System.out.println("查无此人");
            }else{
                System.out.println(name+"的成绩是:"+score);
            }
        }
    }

    public static double selectScoreByName(String[] names, double[] scores, String name) {
        int index = -1;
        for(int i=0;i<names.length;i++){
            if(name.equals(names[i])){
                index = i;
                break;
            }
        }
        if(index==-1){
            return -1;
        }else{
            return scores[index];
        }

    }

    public static void addScore(String[] names,double[] scores) {
        Scanner sca = new Scanner(System.in);
        for(int i=0;i<names.length; i++){
            System.out.println("请输入第"+names[i]+"的成绩:");
            scores[i] = sca.nextDouble();
        }
    }

    public static void addStudent(String[] names){
        Scanner sca = new Scanner(System.in);
        for(int i=0;i<names.length; i++){
            System.out.println("请输入第"+(i+1)+"个学生的姓名:");
            names[i] = sca.next();
        }
    }
}
